<template>
<view class="container">
    <block v-for="(item, index) in pick_address_list" :key="index">
        <view class="address_item active" @tap="useAddress" :data-pick_addr_id="item.pick_addr_id" :data-index="index">
            <view :class="'unradio ' + (item.pick_addr_id == pick_id ? 'radio' : '')"></view>
            <view>
                <lang class="title" keywords="地址"></lang><text class="title">：</text>
                <text>{{item.name}}</text>
            </view>
            <view>
                <lang class="title" keywords="电话"></lang><text class="title">：</text>
                <text>{{item.phone}}</text>
            </view>
            <view>
                <lang class="title" keywords="省市"></lang><text class="title">：</text>
                <text>{{item.province}} {{item.city}} {{item.area}}</text>
            </view>
        </view>
    </block>
</view>
</template>

"<script>
import common from '../../utils/common.js'
var app = getApp();

export default {
  data() {
    return {
      pick_address_list: [],
      mer_id: 0,
      pick_id: 0,
      fromType: ''
    };
  },

  onUnload: function () {},
  onHide: function () {},
  onShow: function () {
	  // #ifdef H5
	  common.hideWxShare()
	  // #endif
  },
  onReady: function () {},
  onLoad: function (options) {
    common.getTxtKey('到店自提地址').then(key => {
      wx.setNavigationBarTitle({
        title: key
      });
    }, () => {});
    common.setMainColor(this);
    this.setData(options);
    common.post('My&a=pick_address', {
      mer_id: this.mer_id,
      fromType: this.fromType,
      store_id: this.store_id
    }, "setPageContent", this);
  },
  components: {},
  props: {},
  methods: {
    useAddress: function (e) {
      wx.setStorageSync('pick_addr_id', e.currentTarget.dataset.pick_addr_id);
      wx.setStorageSync('pick_addr_arr', this.pick_address_list[e.currentTarget.dataset.index]);
      this.setData({
        pick_id: e.currentTarget.dataset.pick_addr_id
      });
      setTimeout(function () {
        wx.navigateBack();
      }, 50);
    },
    setPageContent: function (res) {
      console.log(res);
      this.setData({
        pick_address_list: res
      });
      wx.hideToast();
    },
    setData: function (obj) {
      let that = this;
      let keys = [];
      let val, data;
      Object.keys(obj).forEach(function (key) {
        keys = key.split('.');
        val = obj[key];
        data = that.$data;
        keys.forEach(function (key2, index) {
          if (index + 1 == keys.length) {
            that.$set(data, key2, val);
          } else {
            if (!data[key2]) {
              that.$set(data, key2, {});
            }
          }

          data = data[key2];
        });
      });
    }
  }
};
</script>
<style>
@import "address.css";
</style>